package com.cameron.serviceedu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cameron.serviceedu.client.VodClient;
import com.cameron.serviceedu.entity.EduVideo;
import com.cameron.serviceedu.mapper.EduVideoMapper;
import com.cameron.serviceedu.service.EduVideoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 课程视频 服务实现类
 * </p>
 *
 * @author cameron
 * @since 2022-06-17
 */
@Service
public class EduVideoServiceImpl extends ServiceImpl<EduVideoMapper, EduVideo> implements EduVideoService {


    @Resource
    private VodClient vodClient;


    @Override
    public boolean deleteById(String id) {
        //获取子章节
        EduVideo subChapter = this.getById(id);
        //获取视频id
        String videoSourceId = subChapter.getVideoSourceId();
        //若视频id不为空则删除视频
        if (StringUtils.isNotEmpty(videoSourceId)) {
            //调用client的方法删除视频
            vodClient.deleteVideo(videoSourceId);
        }
        //删除数据库中子章节数据
        return this.removeById(id);
    }
}
